from django.db import models
from .knowledge_point import KnowledgePoint
from .chapter import Chapter
from django.contrib.auth.models import User
from .base_model import BaseModel
from .subject import Subject
from ckeditor_uploader.fields import RichTextUploadingField

class Mistake(BaseModel):
    title = models.CharField(default="标题", max_length=200, verbose_name="标题", blank=False, null=False)
    STAR_CHOICES = [
        (1, '1星'),
        (2, '2星'),
        (3, '3星'),
        (4, '4星'),
        (5, '5星'),
    ]
    star_rating = models.PositiveSmallIntegerField('星级', choices=STAR_CHOICES, default=3)
    citation_count = models.IntegerField('引用次数', default=0)
    """学生错题本模型"""
    id = models.AutoField(primary_key=True, verbose_name='ID')
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE, related_name='mistakes', verbose_name="学科")
    chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE, related_name='mistakes', verbose_name='章节')
    knowledge_point = models.ForeignKey(KnowledgePoint, on_delete=models.CASCADE, related_name='mistakes', verbose_name='知识点')
    question =RichTextUploadingField(config_name='custom',verbose_name='题目')
    answer = RichTextUploadingField(config_name='custom',verbose_name='答案')

    create_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='mistakes', verbose_name="编辑教师")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    def __str__(self):
        return f"{self.subject.name} - {self.chapter}"

    class Meta:
        verbose_name = "错题本"
        verbose_name_plural = "错题本"
        ordering = ['-created_at']
